package com.xfreelance.qcshop.service;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xfreelance.qcshop.entity.User;
import com.xfreelance.qcshop.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    public void add(User user) {
        Timestamp timestamp = DateUtil.date().toTimestamp();
//        user.setCreateTime(timestamp);
        user.setLastLoginTime(timestamp);
        user.setStatus(1);;
        userMapper.insert(user);
    }

    public void update(User user) {
//        user.setUpdateTime(DateUtil.date().toTimestamp());
        userMapper.updateById(user);
    }

    public User findByOpenId(String openId) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("wx_open_id", openId);
        return userMapper.selectOne(queryWrapper);
    }
}
